package erfgame.core.graphics.renderer;


import erfgame.core.CompassDirection;
import erfgame.core.Rotation;
import erfgame.core.entity.Entity;
import erfgame.core.entity.StatefulEntity;
import erfgame.core.world.World;

public class DynamicStatefulEntityRendererFactory implements
		EntityRendererFactory {
	
	private CompassDirection orientation;
	private RenderEntityRendererFactoryAdapter rendererFactory;
	private EntityRenderer defaultRenderer;
	
	public DynamicStatefulEntityRendererFactory( RenderEntityRendererFactoryAdapter rendererFactory, EntityRenderer defaultRenderer ) {
		this( rendererFactory, defaultRenderer, null );
	}
	
	public DynamicStatefulEntityRendererFactory( RenderEntityRendererFactoryAdapter rendererFactory, EntityRenderer defaultRenderer, CompassDirection orientation ) {
		this.rendererFactory = rendererFactory;
		this.defaultRenderer = defaultRenderer;
		this.orientation = orientation;
	}

	public EntityRenderer getRenderer(World world, Entity entity, Rotation viewRotation) {
		EntityRenderer defaultRenderer = ((PrototypeEntityRenderer)this.defaultRenderer).spawn(world, entity);
		//defaultRenderer.setEntity(entity);
		return new DynamicStatefulEntityRenderer(
				world, 
				(StatefulEntity)entity,
				this.rendererFactory,
				defaultRenderer, 
				orientation, 
				viewRotation
		);
	}

	public CompassDirection getOrientation() {
		return orientation;
	}

	public void setOrientation(CompassDirection orientation) {
		this.orientation = orientation;
	}
}
